package com.yunhe.inspect.controller;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.inspect.domain.DataInspectOrder;
import com.yunhe.inspect.model.*;
import com.yunhe.inspect.service.DataInspectOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.yunhe.common.model.ResultObject;

import java.text.ParseException;
import java.util.List;

/**
 * @description 巡检工单表
 * @author misty
 * @date 2021-11-10
 */
@Api(value = "DataInspectOrder", description = "巡检工单表维护", tags = {"巡检工单"})
@RestController
@RequestMapping(value = "/dataInspectOrder")
public class DataInspectOrderController {

    @Autowired
    private DataInspectOrderService dataInspectOrderService;

    /**
     * 新增
     * @author misty
     * @date 2021/11/10
     **/
//    @ApiOperation("新增巡检工单表")
//    @PostMapping("/createDataInspectOrder")
//    public ResponseEntity<ResultObject> createDataInspectOrder(@RequestBody DataInspectOrder dataInspectOrder){
//        dataInspectOrderService.createDataInspectOrder(dataInspectOrder);
//        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
//    }

    /**
     * 刪除
     * @author misty
     * @date 2021/11/10
     **/
    @ApiOperation("根据id批量删除巡检工单")
    @PostMapping("/deleteDataInspectOrderByIds")
    public ResponseEntity<ResultObject> deleteDataInspectOrderByIds(@RequestBody List<Integer> ids) throws ArgumentErrorException {
        dataInspectOrderService.deleteDataInspectOrderByIds(ids);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("根据查询条件全部删除")
    @PostMapping("/deleteDataInspectOrderByQueryCondition")
    public ResponseEntity<ResultObject> deleteDataInspectOrderByQueryCondition(@RequestBody DataInspectOrderQueryCondition dataInspectOrderQueryCondition) throws ArgumentErrorException {
        dataInspectOrderService.deleteDataInspectOrderByQueryCondition(dataInspectOrderQueryCondition);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

//    /**
//     * 更新
//     * @author misty
//     * @date 2021/11/10
//     **/
//    @ApiOperation("更新巡检工单表")
//    @PostMapping("/updateDataInspectOrder")
//    public ResponseEntity<ResultObject> updateDataInspectOrder(@RequestBody DataInspectOrder dataInspectOrder){
//        dataInspectOrderService.updateDataInspectOrder(dataInspectOrder);
//        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
//    }

    /**
     * 查询 根据主键 id 查询
     * @author misty
     * @date 2021/11/10
     **/
    @ApiOperation("根据id查询巡检工单表")
    @GetMapping("/findDataInspectOrderById")
    public ResponseEntity<ResultObject<DataInspectOrderDetailVo>> findDataInspectOrderById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataInspectOrderService.findDataInspectOrderById(id)),HttpStatus.OK);
    }

    @ApiOperation("查询巡检工单列表")
    @PostMapping("/findDataInspectOrder")
    public ResponseEntity<ResultObject<List<DataInspectOrderVo>>> findDataInspectOrder(@RequestBody DataInspectOrderQueryCondition dataInspectOrderQueryCondition) throws ArgumentErrorException {
        PageResult pageResult = dataInspectOrderService.findDataInspectOrder(dataInspectOrderQueryCondition);
        return new ResponseEntity(new ResultObject<>(pageResult), HttpStatus.OK);
    }

    @ApiOperation("App根据条件获取巡检工单列表")
    @PostMapping("/getDataInspectOrderByConditionApp")
    public ResponseEntity<ResultObject<DataInspectOrder>> getDataInspectOrderByConditionApp(@RequestBody InspectOrderAppCondition inspectOrderAppCondition) throws ArgumentErrorException {
        PageResult dataInspectOrderByConditionApp = dataInspectOrderService.getDataInspectOrderByConditionApp(inspectOrderAppCondition);
        return new ResponseEntity<>(new ResultObject(dataInspectOrderByConditionApp),HttpStatus.OK);
    }

    @ApiOperation("App根据id查询巡检工单")
    @GetMapping("/findDataInspectOrderByIdApp")
    public ResponseEntity<ResultObject<AppDetailVO>> findDataInspectOrderByIdApp(@RequestParam(value = "inspectOrderId",required = true) int inspectOrderId){
        return new ResponseEntity<>(new ResultObject(dataInspectOrderService.findDataInspectOrderByIdApp(inspectOrderId)),HttpStatus.OK);
    }

    /**
     * judgeBO targetStatus传参
     * 完成："01"-已完成
     * 开具整改单："03"-待复审
     * */
    @ApiOperation("App评审")
    @PostMapping("/judge")
    public ResponseEntity<ResultObject> judge(@RequestBody JudgeBO judgeBO) throws ArgumentErrorException {
        dataInspectOrderService.judge(judgeBO);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

    @ApiOperation("App整改")
    @PostMapping("/rectifyReform")
    public ResponseEntity<ResultObject> rectifyReform(@RequestBody RectifyReformBO rectifyReformBO) throws ParseException, ArgumentErrorException {
        dataInspectOrderService.rectifyReform(rectifyReformBO);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

    @ApiOperation("App查看历史整改记录")
    @GetMapping("/getRectificationHistory")
    public ResponseEntity<ResultObject<List<RectificationHistoryVO>>> getRectificationHistory(@RequestParam(value = "inspectOrderId",required = true) int inspectOrderId){
        return new ResponseEntity<>(new ResultObject(dataInspectOrderService.getRectificationHistory(inspectOrderId)),HttpStatus.OK);
    }

    /**
     * targetStatus传参
     * 完成："01"-已完成
     * 再次整改："03"-待复审
     * */
    @ApiOperation("App复审")
    @PostMapping("/review")
    public ResponseEntity<ResultObject> review(@RequestBody ReviewBO reviewBO) throws ArgumentErrorException {
        dataInspectOrderService.review(reviewBO);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

/*    @ApiOperation("计算剩余天数")
    @PostMapping("/calculateRemainingDays")
    public ResponseEntity<ResultObject> calculateRemainingDays() throws ParseException {
        dataInspectOrderService.calculateRemainingDays();
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }*/

    @ApiOperation("App评审+复审+整改（评审不合格和复审不合格）")
    @PostMapping("/judgeRectifyReform")
    public ResponseEntity<ResultObject> judgeRectifyReform(@RequestBody RectifyReformBO rectifyReformBO) throws ParseException, ArgumentErrorException {
        dataInspectOrderService.judgeRectifyReform(rectifyReformBO);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

}